<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 订单团期表模型类
 * Created by PhpStorm.
 * User: 66diqiu-li
 * Date: 14-8-1
 * Time: 上午11:09
 */
class Order_Ordergodate_model extends CI_Model{

    /**
     * 更新数据
     * @param array $data  数组
     * @param mixed $where 查询条件 array|string
     * @return boolean 返回数据 true/false
     */
    public function edit_row($data,$where){
        $table = $this->_get_table_name();
        if(!empty($where)) $this->db->where($where, NULL, FALSE);
        return $this->db->update($table,$data);
    }

    /**
     * 添加数据
     * @param array $data 数组
     * @return mixed 返回数据 false/[>0]
     */
    public function add_row($data){
        $table = $this->_get_table_name();
        if(is_array($data)){
            if($this->db->insert($table,$data)){
                return $this->db->insert_id();
            }else{
                return false;
            }
        }
        return false;
    }

    /**
     * 查询单条记录
     * @param mixed $where 查询条件 array|string
     * @param string $field 获取到的字段
     * @return mixed 返回数据
     */
    public function get_row($where,$field='*'){
        $table = $this->_get_table_name();
        if(!empty($where)) $this->db->where($where, NULL, FALSE);
        if(!empty($field)) $this->db->select($field);
        $query = $this->db->get($table,1);
        return $query->row_array();
    }

    /**
     * 删除内容
     * @param mixed $where 查询条件 array|string
     * @return bool 返回数据
     */
    public function remove_row($where){
        $table = $this->_get_table_name();
        if(!empty($where))return $this->db->delete($table,$where);
        return false;
    }

    /**
     * 根据条件获取游客信息表
     * @param mixed $where 查询条件
     * @param string $field 获取字段
     * @return array $data 返回数据
     */
    public function get_list($where='',$field=''){
        $table = $this->_get_table_name();
        if(!empty($where))$this->db->where($where, NULL, FALSE);
        if(!empty($field))$this->db->select($field);
        $query = $this->db->get($table);
        $data = array();
        foreach($query->result_array() as $row){
            $data[] = $row;
        }
        return $data;
    }

public function get_zuowei($go_id,$order_id){
    $sql = "select group_concat(a.zhanzuo) as zhanzuo from ".$this->_get_table_name()." as a left join ".$this->db->dbprefix('order_info')." as b on b.order_id=a.order_id where a.zhanzuo is not null and a.go_id=$go_id and a.order_id<>$order_id and b.order_status<>3 ";
    $query = $this->db->query($sql);
    $res   = $query->row_array();
    $sql2  = "select seat_num from ". $this->db->dbprefix("line_go")." where go_id=$go_id";
    $query2 = $this->db->query($sql2);
    $num    = $query2->row_array();
    $res['seat_num'] = $num['seat_num'];
    $res['zhanzuo_array'] = empty($res['zhanzuo'])?array():explode(",",$res['zhanzuo']);
    return $res;

}

    /**
     * 获取数据表名称
     */
    private function _get_table_name(){
        $table = $this->db->dbprefix("order_go_date");
        return $table;
    }
}